/**
 * 自定义左侧工具栏
 */
import {assign} from "min-dash";
// import {
//   appendTo,
//   classes,
//   create,
//   innerSVG
// } from 'tiny-svg';
export default function CustomPalette(
  palette,
  create,
  elementFactory,
  handTool,
  lassoTool,
  spaceTool,
  globalConnect,
  translate,
  paletteContainer,
  paletteEntries
) {
  this.create = create;
  this.elementFactory = elementFactory;
  this.handTool = handTool;
  this.lassoTool = lassoTool;
  this.spaceTool = spaceTool;
  this.globalConnect = globalConnect;
  this.translate = translate;
  this._entries = paletteEntries // 传入的工具栏数据
  this._paletteContainer = paletteContainer // 传入的工具栏容器
  palette.registerProvider(this);
}

CustomPalette.$inject = [
  "palette",
  "create",
  "elementFactory",
  "handTool",
  "lassoTool",
  "spaceTool",
  "globalConnect",
  "translate",
  'config.paletteContainer',
  'config.paletteEntries'
];

CustomPalette.prototype.getPaletteEntries = function (element) {
  const {
    create,
    elementFactory,
    handTool,
    lassoTool,
    spaceTool,
    globalConnect,
    translate
  } = this;

  function createAction(type, group, className, title, options,imageUrl) {
    function createListener(event) {
      var shape = elementFactory.createShape(assign({type: type}, options));

      if (options) {
        shape.businessObject.di.isExpanded = options.isExpanded;
      }

      create.start(event, shape);
    }

    var shortType = type.replace(/^bpmn:/, "");

    return {
      group: group,
      className: className,
      title: title || translate("Create {type}", {type: shortType}),
      imageUrl,
      action: {
        dragstart: createListener,
        click: createListener
      }
    };
  }

  return {
    // 'hand-tool': {
    //   group: 'tools',
    //   className: 'bpmn-icon-hand-tool',
    //   title: '激活抓手工具',
    //   action: {
    //     click: function (event) {
    //       handTool.activateHand(event);
    //     }
    //   }
    // },
    // "lasso-tool": {
    //   group: "tools",
    //   className: "bpmn-icon-lasso-tool",
    //   title: "激活套索工具",
    //   action: {
    //     click: function (event) {
    //       lassoTool.activateSelection(event);
    //     }
    //   }
    // },
    // 'space-tool': {
    //   group: 'tools',
    //   className: 'bpmn-icon-space-tool',
    //   title: translate('Activate the create/remove space tool'),
    //   action: {
    //     click: function (event) {
    //       spaceTool.activateSelection(event);
    //     }
    //   }
    // },
    // 'global-connect-tool': {
    //   group: 'tools',
    //   className: 'bpmn-icon-connection-multi',
    //   title: translate('Activate the global connect tool'),
    //   action: {
    //     click: function (event) {
    //       globalConnect.start(event);
    //     }
    //   }
    // },
    //
    // "tool-separator": {
    //   group: "tools",
    //   separator: true
    // },

    "create.start-event": createAction(
      "bpmn:StartEvent",
      "event",
      "",//bpmn-icon-start-event-none
      "创建开始节点",
      '',
      require('./kaishijiedian.png')
    ),
    "create.end-event": createAction(
      "bpmn:EndEvent",
      "event",
      "",//bpmn-icon-end-event-none
      "创建结束节点",
      '',
      require('./jieshu.png')
    ),
    "create.user-task": createAction(
      "bpmn:UserTask",
      "activity",
      "",//bpmn-icon-user-task
      "创建用户任务",
      '',
      require('./yonghu.png')
    ),
    "create.exclusive-gateway": createAction(
      "bpmn:ExclusiveGateway",
      "gateway",
      "",//bpmn-icon-gateway-xor
      "创建排他网关",
      '',
      require('./paita.png')
    ),
    "tool-separator": {
      group: "tools",
      separator: true
    },
  };
};
